/*
 * @author wyp
 * @create 21-03-28
 * @desc 获取手机屏幕宽高 及 底部 顶部安全高度
 */

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class ScreenUI {
  static double screenW = 360;
  static late BuildContext context;

  static MediaQueryData get mediaQuery =>
      MediaQueryData.fromView(View.of(context));

  static double get width {
    return screenW;
  }

  static double get height {
    return mediaQuery.size.height;
  }

  static double get scale {
    return mediaQuery.devicePixelRatio;
  }

  static double get textScaleFactor {
    return mediaQuery.textScaleFactor;
  }

  static double get topSafeHeight {
    return mediaQuery.padding.top;
  }

  static double get bottomSafeHeight {
    return mediaQuery.padding.bottom;
  }

  static void updateStatusBarStyle(SystemUiOverlayStyle style) {
    SystemChrome.setSystemUIOverlayStyle(style);
  }

  static double getScaleSp(BuildContext context, double fontSize) {
    if (getScreenW(context) == 0.0) {
      return fontSize;
    }
    return fontSize * getScreenW(context) / 375;
  }

  /// screen width
  /// 当前屏幕 宽
  static double getScreenW(BuildContext context) {
    final MediaQueryData mediaQuery = MediaQuery.of(context);
    return mediaQuery.size.width;
  }

  static void initScreenUI(BuildContext ctx) {
    final MediaQueryData _mediaQuery = MediaQuery.of(ctx);
    context = ctx;
    screenW = _mediaQuery.size.width;
  }
}
